<template>
    <div>
        <!-- {{resourcelist}} -->
        <ul>
            <li v-for="i in resourcelist" :key="i.name">
                <router-link :to="{'path':i.url}">{{i.name}}</router-link>
            </li>
        </ul>
    </div>
</template>

<script>
import {reactive} from 'vue'
export default {
    setup() {
        let customerlist = reactive({'data':[{'name':'234'}]})
        let usersid = localStorage.getItem('uid')

         //初始化websocket
         const initWebsocket=()=>{
            let socket = new WebSocket('ws://127.0.0.1:8000/web_conn/'+usersid)
            //建立
            socket.onopen=function(){
                console.log('建立连接')
            }
            //接收消息
            socket.onmessage=function(msg){
                // customerlist.data=JSON.parse(msg.data)
                console.log(msg.data)
            }
            //关闭
            socket.close=function(e){
                console.log(e)
                console.log('close')
            }
        }


        return{
            customerlist,
            initWebsocket
        }
    },
    data() {
        return {
            resourcelist:JSON.parse(localStorage.getItem('resourcelist'))
        }
    },
    methods: {

    },
    mounted() {
        this.initWebsocket()
    }
}
</script>

<style scoped>

</style>
